package com.zmj.framework.base.entity;

import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldNameConstants;
import lombok.experimental.SuperBuilder;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 如果表涉及唯一索引，继承此类
 *
 * @author lzy
 * @since 2023-11-27
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
public class BasicUniqueEntity implements IEntity, Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "id")
    @TableId(type = IdType.AUTO)
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    @ApiModelProperty(value = "创建人名称")
    @TableField(fill = FieldFill.INSERT)
    @ExcelProperty("创建人名称")
    private String createUserName;

    @ApiModelProperty(value = "创建人工号")
    @TableField(fill = FieldFill.INSERT)
    @ExcelProperty("创建人工号")
    private String createUser;

    @ApiModelProperty(value = "创建时间")
    @TableField(fill = FieldFill.INSERT)
    @ExcelProperty("创建时间")
    private LocalDateTime createTime;

    @ApiModelProperty(value = "更新人", hidden = true)
    @TableField(fill = FieldFill.INSERT_UPDATE, select = false)
    @ExcelProperty("更新人")
    private String updateUser;

    @ApiModelProperty(value = "更新时间", hidden = true)
    @TableField(fill = FieldFill.INSERT_UPDATE, select = false)
    @ExcelProperty("更新时间")
    private LocalDateTime updateTime;

    @ApiModelProperty(value = "是否删除:0未删除;非0已删除", hidden = true)
    @TableLogic(value = "0", delval = "id")
    @TableField(fill = FieldFill.INSERT, select = false)
    private Long deleteFlag;
}
